<html> 

	<%= form_tag("search", :method => "get") do %>
	  <%= text_field_tag(:query, "#{@query}", :style => "height:40px; width:150px",
	  									 :placeholder => 'Search') %>
	  <%= submit_tag('Search', :class => 'btn pull-right', :style => "height:40px;",) %>
	<% end %>


	<% if @query.nil? or @query == ''%>
		<h5> No results </h5>
	<% else %>
		<ul>
			<% @resulted_users.each do |member| %>
				<li> <%= if member.name.nil?  then member.email.split('@').first else "#{member.name}  (#{member.email})"  end %> </li>
				
				<%=	if member.friends.include? @user or member.blocked? @user
					link_to 'Remove friendship',{:controller => 'friendships',
						:action => 'remove', 
						:friend_id => member.id, 
						:query_forward => @query}, 
						class: "btn btn-danger btn-small",
						  	

				elsif @user.invited_by? member  
					'Requested Friendship'

				elsif @user.invited? member and not member.blocked? @user
						link_to 'Remove request',{:controller => 'friendships',
						:action => 'remove_request', 
						:friend_id => member.id,
						:query_forward => @query
						}, 
						class: "btn btn-warning btn-small",  	

				else 
					link_to 'Request friendship',{:controller => 'friendships',
							:action => 'create',
							:friend_id => member.id, 
							:query_forward => @query
							},
						class: "btn btn-success btn-small", style: "margin:", 
						

				end %>

			<% end %>	
		</ul>
	<% end %>
	
	<div style="margin:2%;">
		<%= link_to 'Friendlist',{:controller => 'friendships',
			:action => 'index'}, 
			class: "btn btn-small" %>
	</div>

	<% if @resulted_users.count > 5 %>
		<div class="apple_pagination">
			<%= will_paginate @resulted_users, :container => false %>
		</div>
	<% end %>

</html>